package xm;

import chapter5.entity.Admin;
import chapter5.service.AdminService;
import chapter5.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/sss")
public class cxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理Get请求
        //处理请求的代码
        request.setCharacterEncoding("utf-8");
        //设置相应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");




        AdminService adminService=new AdminServiceImpl();
        List<Admin> list=adminService.selct();
        StringBuffer sb=new StringBuffer();
        sb.append("[");
        for (int i=0;i<list.size();i++){
            sb.append(list.get(i).toString());
            if (i!=list.size()-1){
                sb.append(",");
            }
        }
        sb.append("]");
        PrintWriter out=response.getWriter();
        out.println(sb);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
